{extend name="/fool" /}
{block name="css"}
<link rel="stylesheet" href="/css/admin/order_two.css">
<style>
    #page{
        position: relative;
        display: inline-block;
        left:30%;
        margin-left:-50px;
        padding:50px 0;
    }
</style>
{/block}
{block name="menu_content"}
<div id="one">
    <form class="layui-form" action="" method="post">
        <ul>
            <li>
                <div class="layui-input-inline">
                    <div class="layui-input-inline">
                        <input type="text" name="time" class="layui-input" id="test1" placeholder="开始时间 至 结束时间">
                    </div>
                </div>
                <div class="layui-input-inline">
                    <input type="text" name="username" autocomplete="off" class="layui-input" placeholder="租赁人">
                </div>
                <div class="layui-input-inline">
                    <select name="status">
                        <option value="">状态</option>
                        <option value="1">开启</option>
                        <option value="2">关闭</option>
                    </select>
                </div>
                <button type="Submit" class="layui-btn">筛选</button>
                {if $login['admin'] == 1}
                <button type="button" class="add layui-btn">添加</button>
                {/if}
            </li>
        </ul>
    </form>
</div>
<div>
    <table>
        <tr>
            <th>id</th>
            <th>机台名称</th>
            <th>租赁人</th>
            <th>设备管理人</th>
            <th>状态</th>
            <th class="last">操作</th>
        </tr>
        {if isset($list)}
        {foreach $list as $v}
        <tr class="list">
            <td>{$v.id}</td>
            <td>{$v.name}</td>
            <td>{$v.user.username}</td>
            <td>
                {if $v.userpid.username}
                {$v.userpid.username}
                {else}
                无
                {/if}
            </td>
            <td>
                {if $v.status == 1}
                开启
                {elseif $v.status ==2}
                关闭
                {/if}
            </td>
            <td>
                <button sid="{$v.id}" type="button" class="viewbu layui-btn">详情</button>
            </td>
        </tr>
        {/foreach}
        {/if}
    </table>
    <div id="page">
        {if isset($list)}
        {$page|raw}
        {/if}
    </div>
</div>
<script>
    $(".add").click(function(){
        location.href = "{:url('add')}"
    })
    layui.use('form', function(){
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function(data){
            layer.msg(JSON.stringify(data.field));
            return false;
        });
    });
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#test1'
            ,type: 'month'
            ,range: '至'
            ,format: 'yyyy-MM'
        });
    });
    $(".viewbu").click(function(){
        var id = $(this).attr('sid');
        location.href = "{:url('upload')}" + '?id=' + id;
    })
    layui.use('laypage', function(){
        var laypage = layui.laypage;
        //执行一个laypage实例
        laypage.render({
            elem: 'page'
            ,count: "{$count}"
            ,curr:"{$curl}"
            ,last:"{$groups}"
            ,limit:"{$limit}"
            ,layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            ,jump: function(obj,first){
                console.log(obj)
                if(!first){
                    var url = "{:url('index',['id'=>5,'index'=>0])}" + '&page=' + obj.curr + '&limit=' + obj.limit + '&curr=' + obj.curr;
                    location.href = url;
                }
            }
        });
    });
</script>
{/block}